package 链表.双向.基础;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;

public class Traversal {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //1.
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        //2
        for (int x : list){
            System.out.print(x+" ");
        }
        System.out.println();
        //3
        Iterator<Integer> iterator = list.listIterator();//传数据
        while (iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
        System.out.println();
        //4
        ListIterator<Integer> listIterator = list.listIterator(list.size());
        while (listIterator.hasPrevious()){
            System.out.print(listIterator.previous()+" ");
        }
        System.out.println();
    }
}
